package bean;

import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;
import lombok.ToString;

/*
final 字段：final 字段默认不会生成 Setter 方法。
static 字段：静态字段不会生成 Getter/Setter。
其他注解影响：@ToString和@EqualsAndHashCode默认包含所有非static字段，需通过exclude参数排除字段。
 */
@Data
@ToString
public class Account {
    @Setter(AccessLevel.NONE)
    private int id;
    private double balance;
    private double annualInterestRate;
    private static int init = 1001;//用于自动生成id

    public double getMonthlyInterest() {
        return this.annualInterestRate / 12;
    }

    public void withdraw(double money) {
        if (this.balance < money) {
            System.out.println("余额不足，仅取出" + this.balance + "元。");
            this.balance = 0;
        } else {
            this.balance -= money;
            System.out.println("取款成功！取款金额为：" + money + "元。");
        }
    }

    public void deposit(double money) {
        this.balance += money;
        System.out.println("存款成功！存款金额为：" + money + "元。");
    }

    public Account() {
        this.id = init++;
    }

    public Account(double balance, double annualInterestRate) {
        this();
        this.balance = balance;
        this.annualInterestRate = annualInterestRate;
    }
}
